from google.appengine.ext import db

class OAuthRequestToken(db.Model):
    """OAuth Request Token."""

    service = db.StringProperty()
    oauth_token = db.StringProperty()
    oauth_token_secret = db.StringProperty()
    oauth_verifier = db.StringProperty()
    created = db.DateTimeProperty(auto_now_add=True)

class OAuthAccessToken(db.Model):
    """OAuth Access Token."""

    service = db.StringProperty()
    specifier = db.StringProperty()
    oauth_token = db.StringProperty()
    oauth_token_secret = db.StringProperty()
    created = db.DateTimeProperty(auto_now_add=True)
    
    @staticmethod
    def get_current_token(handler):
        from sessionhandling.sessioncookie import SessionCookie
        
        key = SessionCookie.get_cookie('oauth.projectplace', handler)
        return OAuthAccessToken.get_by_key_name(key).oauth_token